import { _decorator, Component, Label, Node, ProgressBar } from 'cc';
import { BaseView } from '../../../framework/ui/BaseView';
import GlobalData from '../../GlobalData';
import { ViewShowType } from '../../../framework/ui/ViewShowType';
import { ViewLayerDefine } from '../../../framework/ui/VewLayerDefine';
import { LogMgr } from '../../../framework/log/LogMgr';
import { uibind } from '../../../framework/ui/UIDecorator';
import { toRef, toRefs } from '@vue/reactivity';
const { ccclass, property } = _decorator;

@ccclass('LoadingView')
export class LoadingView extends BaseView {

    @uibind("+process",ProgressBar)
    private process_bar:ProgressBar;
    @uibind("+process/+process_label",Label)
    private process_label:Label;
    @uibind("+process/+process_text",Label)
    private process_text:Label;

    constructor() {
        super();
        this.showType = ViewShowType.ALONE;
        this.layer = ViewLayerDefine.Laoding;
    }
    public init(): void {
        console.log("LoadingView init");
    }


    beforeShow(): void {
        let {loadingPercent,loadingText} = toRefs(GlobalData.Ins.loadingViewData);
        loadingText.value = ""
        loadingPercent.value  = 0;
        this.addEffect(() => {
            this.process_bar.progress = loadingPercent.value;
            this.process_label.string = loadingPercent.value + "%";
            LogMgr.debug("加载进度："+loadingPercent.value)
        });
        this.addEffect(() => {
            this.process_text.string = loadingText.value;
        });

    }
}


